# Maintainer: Andreas 'Segaja' Schleifer <segaja at archlinux dot org>

_gemname='rails-html-sanitizer'
pkgname="ruby-${_gemname}"
pkgver=1.4.3
pkgrel=1
pkgdesc='HTML sanitization for Rails applications'
arch=('any')
url='https://github.com/rails/rails-html-sanitizer'
license=('MIT')
options=(!emptydirs)
depends=('ruby' 'ruby-loofah')
makedepends=('ruby-bundler' 'ruby-minitest' 'ruby-rake')
checkdepends=('ruby-rails-dom-testing')
source=("${url}/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha512sums=('4a48e05efb2bf3bef885b6524501446fdff897a68a273f712bab2881dbb4c3e81b736bfd45c3a17653330c830e06bedc63ceb6e2290bc449be715794459e104b')

prepare() {
  cd "${_gemname}-${pkgver}"

  # update gemspec/Gemfile to allow newer version of the dependencies
  sed -r 's|~>|>=|g' -i "${_gemname}.gemspec" Gemfile
}

build() {
  cd "${_gemname}-${pkgver}"

  rake build
}

check() {
  cd "${_gemname}-${pkgver}"

  rake test
}

package() {
  cd "${_gemname}-${pkgver}"

  local _gemdir="$(gem env gemdir)"

  gem install --ignore-dependencies --no-user-install -i "${pkgdir}/${_gemdir}" -n "${pkgdir}/usr/bin" "pkg/${_gemname}-${pkgver}.gem"

  rm "${pkgdir}/${_gemdir}/cache/${_gemname}-${pkgver}.gem"

  install -D -m644 MIT-LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
